package com.sua.mybatis;

import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.web.servlet.support.RequestContextUtils;

import com.mysql.jdbc.PreparedStatement;

public class JdbcTest {
	public static void main(String[] args) {
		java.sql.Connection connection = null;
		PreparedStatement preparedStatement = null;
		ResultSet resultSet = null;

		try {
			Class.forName("com.mysql.jdbc.Driver");
			// connection =
			// DriverManager.getConnection("jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8",
			// "root", "123456");
			connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/wayz?characterEncoding=utf-8", "root",
					"");
			String sql = "select * from user where name  = ?";
			preparedStatement = (PreparedStatement) connection.prepareStatement(sql);
			preparedStatement.setString(1, "admin");
			resultSet = preparedStatement.executeQuery();
			while (resultSet.next()) {

				System.out.println(resultSet.getString("id") + "  " + resultSet.getString("name"));
			}
			

		} catch (Exception e) {
			System.out.println(e.getMessage());
			// TODO: handle exception
		} finally {
			if (resultSet != null) {

				try {
					resultSet.close();

				} catch (Exception e2) {
					// TODO: handle exception
				}
			}
			if (preparedStatement != null) {
				try {
					preparedStatement.close();
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if (connection != null) {

				try {
					connection.close();
				} catch (Exception e2) {
					// TODO: handle exception
				}
			}

		}

	}

}
